import pygame
from pygame.locals import *
import sys
import Gif

LEFT = 1
RIGHT = 2
UP = 3
DOWN = 4


class MovePath:
    '''
    :parameter direction方向  a 加速度 time时间
    '''
    def __init__(self, direction, a, time):
        self.direction = direction
        self.a = a
        self.time = time


class Worf:

    def __init__(self, img, x, y, move_paths):
        self.img = img
        self.x = x
        self.y = y
        self.move_paths = move_paths

    def move(self):
        for item in self.move_paths:
            dir = item.direction
            if dir == LEFT:
                self.x = self.x - self.x * item.a


pygame.display.init()
screen = pygame.display.set_mode((400, 300))
img = pygame.image.load("farm1.jpg").convert()  # 背景图片
img = pygame.transform.scale(img, (img.get_width() * 3, img.get_height() * 3))
print(img.get_width(),img.get_height())
imgPos = pygame.Rect((0, 0), (0, 0))

worf = pygame.image.load("worf.png").convert()
worf = pygame.transform.scale(worf, (worf.get_width() * 0.2, worf.get_height() * 0.2))

LeftButton = 0
while 1:
    for e in pygame.event.get():
        if e.type == QUIT: exit(0)
        if e.type == MOUSEMOTION:
            # if e.buttons[LeftButton]:
            #     # clicked and moving
            rel = e.rel
            imgPos.x -= rel[0]
            imgPos.y -= rel[1]
            # if imgPos.x <= 0:
            #     imgPos.x = 0
            # if imgPos.y <= 0:
            #     imgPos.y = 0
            # if imgPos.x >= img.get_width():
            #     imgPos.x = img.get_width()
            # if imgPos.y >= img.get_height():
            #     imgPos.y = img.get_height()
            print(imgPos)
    screen.fill(0)
    screen.blit(img, imgPos)
    # hulk.render(screen, (0, 0))
    screen.blit(worf, (0, 0))

    screen.blit(worf, (50, 68))
    pygame.display.flip()
    pygame.time.delay(30)